﻿/************************************************************************
* Copyright (c) 2018 All Rights Reserved.
*命名空间：DAL.Base
*文件名： IBaseDal
*创建人： kingling
*创建时间：2018/6/19 12:44:00
*描述
*=======================================================================
*修改标记
*修改时间：2018/6/19 12:44:00
*修改人：kingling
*描述：
************************************************************************/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace DAL.Base
{
    public interface IBaseDal<T> where T : class, new()
    {
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entities"></param>
        /// <param name="isCommit"></param>
        /// <returns></returns>
        bool Add(IEnumerable<T> entities, bool isCommit = true);
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="isCommit"></param>
        /// <returns></returns>
        bool Add(T entity, bool isCommit = true);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="isCommit"></param>
        /// <returns></returns>
        bool Delete(T entity, bool isCommit = true);
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="entities"></param>
        /// <param name="isCommit"></param>
        /// <returns></returns>
        bool Delete(IEnumerable<T> entities, bool isCommit = true);
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entities"></param>
        /// <param name="isCommit"></param>
        /// <returns></returns>
        bool Update(T entities, bool isCommit = true);
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        IQueryable<T> Query(Expression<Func<T, bool>> where);
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="where"></param>
        /// <param name="includes"></param>
        /// <returns></returns>
        IQueryable<T> Query(Expression<Func<T, bool>> where, params Expression<Func<T, object>>[] includes);
        /// <summary>
        /// 无缓存查询
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        IQueryable<T> QueryAsNoTracking(Expression<Func<T, bool>> where, params Expression<Func<T, object>>[] includes);
        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="where"></param>
        /// <param name="paths"></param>
        /// <returns></returns>
        IQueryable<T> Query(Expression<Func<T, bool>> where, params string[] paths);

        /// <summary>
        /// 统计
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        int Count(Expression<Func<T, bool>> where);

        /// <summary>
        /// 分页
        /// </summary>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="where"></param>
        /// <param name="orderby"></param>
        /// <param name="total"></param>
        /// <param name="page"></param>
        /// <param name="IsAsc"></param>
        /// <param name="pageSize"></param>
        /// <param name="includes"></param>
        /// <returns></returns>
        IQueryable<T> QueryByPage<TKey>(Expression<Func<T, bool>> where, Expression<Func<T, TKey>> orderby, out int total, out int pageSize, int page=1,bool IsAsc=true, params Expression<Func<T, object>>[] includes);
        /// <summary>
        /// 提交上下文
        /// </summary>
        /// <returns></returns>
        bool Save();
    }
}

